package com.xzg.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xzg.annotation.XzgController;
import com.xzg.annotation.XzgQualifier;
import com.xzg.annotation.XzgRequestMapping;
import com.xzg.annotation.XzgRequestParam;
import com.xzg.service.XzgService;

@XzgController
@XzgRequestMapping("/Xzg")
public class XzgDemoController {

	@XzgQualifier("XzgServiceImpl")
	private XzgService xzgService;

	@XzgRequestMapping("/query")
	public void query(HttpServletRequest request, HttpServletResponse response, @XzgRequestParam("name") String name,
			@XzgRequestParam("age") String age) {

		try {
			PrintWriter pw = response.getWriter();
			String result = xzgService.query(name, age);
			pw.write(result);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@XzgRequestMapping("/insert")
	public void insert(HttpServletRequest request, HttpServletResponse response) {
		try {
			PrintWriter pw = response.getWriter();
			String result = xzgService.insert("0000");

			pw.write(result);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@XzgRequestMapping("/update")
	public void update(HttpServletRequest request, HttpServletResponse response, String param) {
		try {
			PrintWriter pw = response.getWriter();
			String result = xzgService.update(param);

			pw.write(result);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
